public class ThreadSAdvantage {
    public static  final long count  = 10_0000_0000;
    public static void main(String[] args) throws InterruptedException{
        concurrency();
        serial();
    }

    private  static void concurrency ()throws InterruptedException {
        {
            long begin = System.nanoTime();
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    int a = 0;
                    for (long i= 0; i < count; i++) {
                        a--;
                    }
                }
            });
            thread.start();
            //到此处是用一个线程计算a的值
            int b = 0;
            for (long i= 0; i < count; i++) {
                b--;
            }

            //统计计时
            long end = System.nanoTime();
            double time = (end-begin)*1.0 /1000/1000;
            System.out.printf("并发：%f 毫秒%n",time);
        }
    }
    private  static void serial (){
    long begin = System.nanoTime();
    int a =0;
        for (long i= 0; i < count; i++) {
            a--;
        }
    int b = 0;
        for (long i= 0; i < count; i++) {
            b--;
        }

        //统计时长
        long end = System.nanoTime();
        double time  = (end - begin)*1.0/1000/1000;
        System.out.printf("串行：%f 毫秒%n",time);
}

}